package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.core.domain.R;
import com.smart.common.core.page.PageQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.Car;
import com.smart.system.service.ICarService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 车辆Controller
 * 
 * @author smart
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/car")
@Api(tags = "车辆")
public class CarController extends BaseController
{
    @Autowired
    private ICarService carService;

    /**
     * 查询车辆列表
     */
    @ApiOperation(value = "查询车辆列表")
    //@PreAuthorize("@ss.hasPermi('system:car:list')")
    @GetMapping("/list")
    public R<IPage<Car>> list(Car car, PageQuery pageQuery)
    {
        return R.ok(carService.selectCarList(car,pageQuery));
    }

    /**
     * 获取车辆详细信息
     */
    @ApiOperation(value = "获取车辆详细信息")
    //@PreAuthorize("@ss.hasPermi('system:car:query')")
    @GetMapping(value = "/{id}")
    public R<Car> getInfo(@PathVariable("id") String id)
    {
        return R.ok(carService.selectCarById(id));
    }

    /**
     * 新增车辆
     */
    @ApiOperation(value = "新增车辆")
    //@PreAuthorize("@ss.hasPermi('system:car:add')")
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Integer> add(@RequestBody Car car)
    {
        return R.ok(carService.insertCar(car));
    }

    /**
     * 修改车辆
     */
    @ApiOperation(value = "修改车辆")
    //@PreAuthorize("@ss.hasPermi('system:car:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Integer> edit(@RequestBody Car car)
    {
        return R.ok(carService.updateCar(car));
    }

    @ApiOperation(value = "启用/停用车辆")
    //@PreAuthorize("@ss.hasPermi('system:car:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public R<Boolean> changeStatus(Integer id,Integer status)
    {
        return R.ok(carService.changeStatus(id,status));
    }

    /**
     * 删除车辆
     */
    @ApiOperation(value = "删除车辆")
    //@PreAuthorize("@ss.hasPermi('system:car:remove')")
    @Log(title = "车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable String[] ids)
    {
        return R.ok(carService.deleteCarByIds(ids));
    }
}
